/*
 * main.cpp
 *
 *  Created on: Jul 26, 2010
 *      Author: sdaniele
 */

#define SC_INCLUDE_DYNAMIC_PROCESSES 	//necessary for sc_spawn() to compile
#include "systemc.h"


#include <iostream>
#ifndef NDEBUG
#define DBG_PRINT(x)\
	std::cout << "[debug]:" << (x) << std::endl;
#else
#define DBG_PRINT(x);
#endif

#include <boost/static_assert.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/arithmetic.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/for_each.hpp>

#include <boost/iostreams/device/null.hpp>

namespace mpl=::boost::mpl;

namespace syscpar{namespace test{

bool gl_verbose;	//read-only after parse
inline bool is_verbose(){
	return gl_verbose;
}

}}

#include "common_options.hpp"
#include "backoff.hpp"
#include "process.hpp"
#include "work.hpp"
#include "macros.hpp"

using namespace ::syscpar::test;

template <bool is_thread> void main_impl(common_options& opt){

	#ifdef TEST
	inject_here();
	#else
	#include "wrapper"
	#endif

	if(opt.sim_time()!=NULL)
		sc_start(*opt.sim_time());
	else
		sc_start();
}


int sc_main( int argc, char* argv[] )
{
	common_options opt;
	opt.parse(argc,argv);


	gl_verbose = opt.verbose();
	if(opt.asked_help()) return 0;

	if(opt.use_threads())	main_impl<true>(opt);
	else			main_impl<false>(opt);

	return 0;
}


